﻿using HuiZe.education.Model;
using HuiZe.education.ViewModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Controls;

namespace HuiZe.education.View
{
    /// <summary>
    /// PART_Lesson_Media_Host.xaml 的交互逻辑
    /// </summary>
    public partial class PART_Resource_Media_Host : UserControl
    {
        public PlanLessonViewModel planModel { get; set; }

        public PART_Resource_Media_Host()
        {
            InitializeComponent();
        }
        
        public void Load(respResourceChildModel_Ethan[] _data)
        {
            Reset();
            _model_src = _data;
            _is_selected_default = false;
            if (_data == null) return;

            PART_CoursesItemList.ItemsSource = _data;
        }
        void PART_CoursesResourceItem_Loaded(object sender, RoutedEventArgs e)
        {
            (sender as RadioButton).Checked += PART_CoursesResourceItem_Checked;
            if (!_is_selected_default)
            {
                _is_selected_default = true;
                (sender as RadioButton).IsChecked = new bool?(true);
            }
        }

        void PART_CoursesResourceItem_Checked(object sender, RoutedEventArgs e)
        {
            respResourceChildModel_Ethan _item = ((FrameworkElement)sender).DataContext as respResourceChildModel_Ethan;
            PART_Media.SetData(_item);
        }

        void PART_IsSelected_CoursesResourceItem_Checked(object sender, RoutedEventArgs e)
        {
            var _model = ((CheckBox)sender).DataContext as respResourceChildModel_Ethan;
            planModel.zjkjList3.Add(_model);
        }

        void PART_IsSelected_CoursesResourceItem_Unchecked(object sender, RoutedEventArgs e)
        {
            var _model = ((CheckBox)sender).DataContext as respResourceChildModel_Ethan;
            planModel.zjkjList3.Remove(_model);
        }

        public void Reset()
        {
            PART_Media.Reset();
            PART_CoursesItemList.ItemsSource = null;
        }

        
        bool _is_selected_default;
        respResourceChildModel_Ethan[] _model_src;
    }
}
